<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
</head>
<style>
.mui-btn {
	margin: 5px;
}
</style>
<body>
	<form class="mui-input-group mui-collapse-content">
		<input type="hidden" id="compId" value="${compId}">
		<div class="mui-input-row selectComp">
			<label>公司:</label> <select>
				<option value="">全部</option>
				<c:forEach items="${comps }" var="list">
					<option value="${list.compId }">${list.compName }</option>
				</c:forEach>
			</select>
		</div>
		<div class="mui-input-row selectType">
			<label>类型：</label> <select>
				<option value="">全部</option>
				<option value="0">图片</option>
				<option value="1">视频</option>
				<option value="2">音频</option>
			</select>
		</div>
	</form>
	<div id="leg_table"></div>
	<script type="text/html" id="Bar">
		<a class="mui-btn mui-btn-primary edit">编辑</a>
		<a class="mui-btn mui-btn-primary del">删除</a>
	</script>
	<script type="text/javascript">
    	mui('#offCanvasContentScroll').scroll().scrollTo(0,0);
    
    	$(".mui-title").html("广告资源");
    	
		var data,count;
		var param="";
		var pageNum = 1;
		//公司
		$('.selectComp').on('change',function(){
		    //判断是否选取prompt属性，无返回值；
	        var compId = $(this).find('option:selected').val();
	        stateList = $.legTable({
	        	where:{
	        		compIdParam:compId
        		}
        	})
		});
		
		//类型
		$('.selectType').on('change',function(){
		    //判断是否选取prompt属性，无返回值；
	        var id = $(this).find('option:selected').val();
	        stateList = $.legTable({
	        	where:{
	        		type:id
        		}
        	});
		});
		
		//接收数据
		var stateList = $.legTable({
			limit: 10,			//默认10
			page:1,				//默认1
			id:"#leg_table",	//绑定id
			url:"/publishFile/list",
			cols:[
				{field: 'name', title: '资源名称'},
	            {field: 'des', title: '描述'},
	            {field: 'compName', title: '所属公司'},
	            {field: 'type', title: '类型',templet:function(f){
	            	if(f.type == 0){
	            		return "<span>图片</span>"
	            	}else if(f.type == 1){
	            		return "<span>视频</span>"
	            	}else if(f.type == 2){
	            		return "<span>音频</span>"
	            	}
	            }},
	            {field: 'url', title: '地址',templet:function(f){
	            	return '<a href="'+f.url+'">'+f.url+'</a>';
	            } },
	            {field: 'creatTime', title: '上传时间'},
	            {title: '操作',templet:'#Bar'}
	        ]
		});
		
		//开启a
		mui('body').on('tap','li data a',function(){ 
			let href = this.href
			if(href != "" && href.length > 2){
				window.top.location.href=this.href; 
			}
		});
		
		//添加
		$("#Add").show();
		$("#Add").on("touchstart",function(e){
			$("#Add").hide();
			url = "/publishFile/add";
			window.location.hash = url;
			sessionStorage.setItem("url",url)
		})
		//编辑
		$("#leg_table").on("touchstart", ".table-list .edit", function(e){
			let i = $(this).parent('data').attr("value");
			let url = "/publishFile/edit?fileId="+$.data(i).fileId;
			sessionStorage.setItem("url",url)
			window.location.hash = url;
			sessionStorage.setItem('publishFile', JSON.stringify($.data(i)));
	    });
		 //删除
         $("#leg_table").on("touchstart", ".table-list .del", function(e){
       	    let i = $(this).parent('data').attr("value");
   	    	mui.confirm('确定删除此广告？','温馨提示',function(e) {
				if (e.index == 1) {
					$.get("/publishFile/deleteFile?fileId="+$.data(i).fileId,function(res){
		           		if (!res.success) {
		           			mui.toast(res.message);
		       			}else{
		       				mui.toast("删除成功");
		       				stateList = $.legTable();
		       			}
		           	})
				}
			})
        })

	</script>
</body>
</html>